package com.itheima.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface WaterQualityMapper {

    // 查询最近24小时的每小时数据
    @Select("""
    SELECT AVG(${column}) AS value,
           ANY_VALUE(DATE_FORMAT(record_time, '%Y-%m-%d %H:00:00')) AS time
    FROM ${table}
    WHERE record_time BETWEEN '2025-03-27 10:00:00' AND '2025-03-28 09:00:00'
    GROUP BY time
    ORDER BY time
""")
    List<Map<String, Object>> fetchRealtimeData(@Param("table") String table, @Param("column") String column);


    // 查询最近30天的每日数据
    @Select("""
    SELECT AVG(${column}) AS value,
           ANY_VALUE(DATE_FORMAT(record_time, '%Y-%m-%d %H:00:00')) AS time
    FROM ${table}
    WHERE record_time BETWEEN '2025-02-27 12:00:00' AND '2025-03-28 12:00:00'
    GROUP BY time
    ORDER BY time
""")
    List<Map<String, Object>> fetchHistoryData(@Param("table") String table, @Param("column") String column);
}
